package main

import (
	"log"
	"time"

	smsapi "../"
)

func main() {
	// 创建配置
	config := &smsapi.Config{
		Service: smsapi.ServiceConfig{
			Name:    "SMS API Server",
			Version: "1.0.0",
			Port:    8080,
			Timeout: 30 * time.Second,
		},
		SpaceIoT: smsapi.SpaceIoTConfig{
			Enabled:   true,
			APIURL:    "https://sms.space-iot.net/api/sms/sendByContent",
			Signature: "your_signature",
			SecretKey: "your_secret_key",
			Timeout:   30 * time.Second,
		},
		Retry: smsapi.RetryConfig{
			MaxAttempts: 3,
			InitialDelay: time.Second,
			MaxDelay:     10 * time.Second,
			Multiplier:   2.0,
		},
		RateLimit: smsapi.RateLimitConfig{
			Enabled: true,
			RPS:     10,
			Burst:   20,
		},
		Monitoring: smsapi.MonitoringConfig{
			Enabled: true,
			MetricsPath: "/metrics",
		},
		Security: smsapi.SecurityConfig{
			Enabled: true,
			APIKey:  "your_api_key",
		},
	}

	// 创建SMS服务
	service, err := smsapi.NewSMSService(config)
	if err != nil {
		log.Fatalf("创建SMS服务失败: %v", err)
	}

	// 创建HTTP处理器
	handler := smsapi.NewSMSHandler(service)

	log.Printf("SMS API服务器启动在端口 %d", config.Service.Port)
	log.Println("可用的API端点:")
	log.Println("  POST /api/v1/sms/send - 发送单条短信")
	log.Println("  POST /api/v1/sms/batch - 批量发送短信")
	log.Println("  GET  /api/v1/sms/query/:messageId - 查询短信状态")
	log.Println("  GET  /api/v1/health - 健康检查")
	log.Println("  GET  /api/v1/metrics - 获取指标")
	log.Println("  GET  /api/v1/providers - 获取提供商列表")
	log.Println("  GET  /api/v1/config - 获取配置")
	log.Println("  PUT  /api/v1/config - 更新配置")

	// 启动HTTP服务器
	if err := smsapi.StartHTTPServer(handler, config.Service.Port); err != nil {
		log.Fatalf("启动HTTP服务器失败: %v", err)
	}
}